#include "recordinfo.h"
#include "ui_recordinfo.h"

RecordInfo::RecordInfo(){
}

RecordInfo::RecordInfo(Record record){
    setupUi(this);

    connect(this, SIGNAL(on_recordInfoAccept_clicked()), this, SLOT(checkEdited()));
    connect(this, SIGNAL(on_deleteRecordButton_clicked()), this, SLOT(removeRecord()));

    this->id = record.getid();
    this->record = record;
    this->name = record.getname();
    this->info = record.getinfo();
    this->category = record.getcategory();
    this->datetime = record.getdatetime();
    this->amount = record.getamount();
    this->nameID = record.getnameid();
    edited = false;
    this->setWindowTitle(QString::fromStdString(record.getname()));
    this->recordInfoAmount->setValue(amount);
    this->recordInfoName->setText(QString::fromStdString(record.getname()));
    this->recordInfoDateTime->setDateTime(record.getdatetime());
    this->recordInfoInfo->setText(QString::fromStdString(record.getinfo()));
    setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint);
    layout() -> setSizeConstraint(QLayout::SetFixedSize);
}

void RecordInfo::removeRecord(){
    remove(nameID);
    this->close();
}
void RecordInfo::checkEdited(){
        //modify(nameID, this->id, recordInfoDateTime->dateTime(), recordInfoName->text().toStdString(), recordInfoInfo->toPlainText().toStdString()
          //     , recordInfoCategoryCombo->currentText().toStdString(), recordInfoAmount->value());
        Record r;
        r.setname(recordInfoName->text().toStdString());
        r.setid(record.getid());
        r.setnameid(record.getid().append(" ").append(recordInfoName->text().toStdString()));
        r.setinfo(recordInfoInfo->toPlainText().toStdString());
        r.setcategory(recordInfoCategoryCombo->currentText().toStdString());
        r.setamount(recordInfoAmount->value());
        r.setdatetime(recordInfoDateTime->dateTime());
        modify(this->record, r);
        this->close();
}

